package mysql

import (
	"fmt"
	"goods_srv/appconfig"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

var (
	err error
	DB  *gorm.DB
)

func InitMysql() {
	stu := appconfig.AppConf.MysqlInit
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", stu.User, stu.Pass, stu.Hort, stu.Part, stu.Data)
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		fmt.Println("mysql 连接失败")
		return
	}
	fmt.Println("mysql 连接成功")
	DB.AutoMigrate(new(Goods), new(Order))
}
